package day13;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class Server1 {
    public static void main(String[] args) throws IOException {
        //1.创建服务端对象
        ServerSocket server=new ServerSocket(62157);
        while (true) { //控制多人连接服务
            System.out.println("开始执行一次");
            Socket client = server.accept();//2.等待客户端连接 会阻塞
            System.out.println(client);
            //3.获取输入(读取客户端的数据)和输出流(向客户端写数据)
            InputStream is= client.getInputStream();
            OutputStream os=client.getOutputStream();
            String msg="你连接成功了\n";
            os.write(msg.getBytes());
            BufferedReader br=new BufferedReader(new InputStreamReader(is));
            String result=br.readLine();
            System.out.println("客户端数据"+result);
        }
    }
}
